﻿namespace Furesoft.Styling.Converters
{
    using System.Text.RegularExpressions;

    internal class DegreeConverter : IConverter<Degree>
    {
        #region Public Methods and Operators



        #endregion

        public override Degree Convert(string s)
        {
            string pattern = @"(?<num>[1-9](?:\d{0,2}(?:,\d{3})+|\d*))(?<degree>dg)?";
            Match m = Regex.Match(s, pattern);
            string degree = m.Groups["degree"].Value;
            string num = m.Groups["num"].Value;

            if (degree == "dg")
            {
                return new Degree(float.Parse(num));
            }
            

            return new Degree(float.Parse(s));
        }

        public override string Convert(Degree s)
        {
            return s.value + "dg";
        }
    }
}